from mootdx.quotes import Quotes
from fastapi import Query
# 创建客户端，连接到标准市场
client = Quotes.factory(market='std', multithread=True, heartbeat=True,
                        bestip=False, timeout=15, server=('60.191.117.167', 7709))
# print(client.server)


def get_minutes(tsCode: str, tradeDate: str):
    # 查询分时数据
    data = client.minutes(tsCode, tradeDate)
    return data


def Pget_stocks_minutes(tsCodeList: str = Query(...), tradeDate: str = Query(...)):
    results = {}
    tsCodes = tsCodeList.split(',')
    for tsCode in tsCodes:
        print(tsCode, tradeDate)
        try:
            # 获取分时数据
            minutes_data = get_minutes(tsCode, tradeDate)
            results[tsCode] = minutes_data.to_dict(orient='records')
        except Exception as e:
            print(f"获取 {tsCode, tradeDate} 的分时数据时出错: {e}")
    # client.close()
    return results

# 示例用法
if __name__ == "__main__":


   data = get_minutes('600301','20250718')
   print(data)
